import 'package:flutter/material.dart';


/* 在其子组件的尺寸发生变化时，自动调整自身的尺寸，并且在调整过程中带有动画效果 */
class SizeStatic extends StatefulWidget {
  const SizeStatic({super.key});

  @override
  State<SizeStatic> createState() => _SizeStaticState();
}

class _SizeStaticState extends State<SizeStatic> with SingleTickerProviderStateMixin {
  bool _large = false;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: 300,
      decoration: BoxDecoration(
        border: Border.all(color: Colors.black, width: 1),
        borderRadius: BorderRadius.circular(6)
      ),
      child: Column(
        children: [
          ElevatedButton(
            onPressed: () {
              setState(() {
                _large = !_large;
              });
            },
            child: const Text('切换 size')
          ),

          AnimatedSize(
            duration: const Duration(seconds: 1),
            curve: Curves.easeInOut,
            child: Container(
              color: Colors.amber[100],
              width: _large ? 200 : 100,
              height: _large ? 200 : 100,
              alignment: Alignment.center,
              child: const Text('AnimatedSize'),
            ),
          )
        ],
      ),
    );
  }
}